package main

import "fmt"

func main() {
	// 固定长度数组
	var myArr1 [10]int

	myArr2 := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9}

	for i := 0; i < len(myArr1); i++ {
		fmt.Println(myArr1[i])
	}

	for index, value := range myArr1 {
		fmt.Println(index, value)
	}

	fmt.Printf("%T\n", myArr1)
	fmt.Printf("%T\n", myArr2)

	//silence00 := []int{0, 1, 2}
	//
	//var silence01 []int
	//silence01 = make([]int, 3)
	//
	//var silence02 []int = make([]int, 3)
	//
	//var silence1 []int = []int{1, 2, 3}
	silence11 := make([]int, 3)

	fmt.Printf("silence11 = %v\n%d\n", silence11, len(silence11))

	if silence11 == nil {
		fmt.Println("空切片")
	} else {
		fmt.Println("有空间")
	}

	fmt.Println("==================")

	numbers := make([]int, 3, 5)
	fmt.Printf("%v\n%d\n%d\n", numbers, len(numbers), cap(numbers))
	numbers = append(numbers, 3, 1, 2, 10, 1, 2, 1, 1, 9, 1, 0)
	fmt.Printf("%v\n%d\n%d\n", numbers, len(numbers), cap(numbers))

	fmt.Println("===================")

	var str []int = []int{1, 2, 3}
	fmt.Println(str)
	s1 := str[0:2] // 左闭右开 0 1
	s2 := str[1:3] // 左闭右开 1 2
	fmt.Println(s1)
	fmt.Println(s2)

	s1[0] = 100 // 值拷贝
	fmt.Println(str)
	fmt.Println(s1)

	fmt.Println("==================")

	// copy深拷贝
	ss1 := make([]int, 4)
	copy(ss1, str)
	fmt.Println(str)
	fmt.Println(ss1)
	ss1[0] = 200
	fmt.Println(str)
	fmt.Println(ss1)

}
